<template>
  <div>
    <div v-loading="loadging">登录~{{ $store.state.isLogin }}</div>
    <div>
      <button @click="onlogin">登录</button>
    </div>
  </div>
</template>

<script>
import { asyncRoutes } from "../router/index";
export default {
  data() {
    return {
      loadging: false,
    };
  },

  mounted() {},

  methods: {
    onlogin() {
      this.loadging = true; // 显示 全局loading
      var timer = setTimeout(() => {
        this.$store.commit("login"); // 执行登录 修改 isLogin
        this.$router.addRoutes(asyncRoutes); // 加载动态路由
        this.loadging = false;

        clearTimeout(timer);
        timer = null;
      }, 1000);
    }
  },
};
</script>

<style scoped></style>
